﻿import QtQuick 2.0
import "../components"
import QtCharts 2.3

Rectangle {
    width: parent.width
    height: parent.height
    onVisibleChanged: {
        if(visible){
            var data=CStatMaint.getAllStaticInfo();

            t1.numbv=data["EquOperatingTime"]
            if(data["EquOperatingTime"]>50){
                t1.more=true
            }
            else{
                t1.more=false
            }

            t2.numbv=data["Syringe"]
            if(data["Syringe"]>50){
                t2.more=true
            }
            else{
                t2.more=false
            }

            // 气缸替换为耗材编码统计
//            t3.numbv=data["AirBottle"]
//            if(data["AirBottle"]>50){
//                t3.more=true
//            }
//            else{
//                t3.more=false
//            }

            t4.numbv=data["Turntable"]
            if(data["Turntable"]>50){
                t4.more=true
            }
            else{
                t4.more=false
            }

            t5.numbv=data["RubberPad"]
            if(data["RubberPad"]>50){
                t5.more=true
            }
            else{
                t5.more=false
            }

            beginDate.setText(Qt.formatDateTime(new Date(), "yyyy-MM-dd"))
            endDate.setText(Qt.formatDateTime(new Date(), "yyyy-MM-dd"))

            var partData=CStatMaint.getPercentageStaticInfo(beginDate.getText(),endDate.getText())
            pieSeries.clear();
            if(partData["Syringe"]===0){
                pieSeries.append("气罐",partData["Syringe"])
            }
            else
            {
                pieSeries.append("气罐"+partData["Syringe"]+"%",partData["Syringe"])
                pieSeries.find("气罐"+partData["Syringe"]+"%").labelVisible=true;
            }

            if(partData["AirBottle"]===0){
                pieSeries.append("注射器",partData["AirBottle"])
            }
            else
            {
                pieSeries.append("注射器"+partData["AirBottle"]+"%",partData["AirBottle"])
                pieSeries.find("注射器"+partData["AirBottle"]+"%").labelVisible=true;
            }

            if(partData["Turntable"]===0){
                pieSeries.append("转盘",partData["Turntable"])
            }
            else
            {
                pieSeries.append("转盘"+partData["Turntable"]+"%",partData["Turntable"])
                pieSeries.find("转盘"+partData["Turntable"]+"%").labelVisible=true;
            }

            if(partData["RubberPad"]===0){
                pieSeries.append("胶垫",partData["RubberPad"])
            }
            else
            {
                pieSeries.append("胶垫"+partData["RubberPad"]+"%",partData["RubberPad"])
                pieSeries.find("胶垫"+partData["RubberPad"]+"%").labelVisible=true;
            }
        }
    }
    property int tabnumv: 1
    property int tabnum: 1
    Rectangle{
        y:20*dp
        width: parent.width
        height: 120*dp
        TJBYTop{
            id:t1
            x:20*dp
            y:0*dp
            width: (parent.width-80*dp)/5
            picpath:"qrc:/picture/tj_p1.png"
            topv:"设备运行时长（h）"
            numbv: "14"
            dcolor: tabnumv===1?"#FF7F0B":"#DEDEDE"
            onAllcli: {
                tabnum=1
                tabnumv=1
            }
        }
        TJBYTop{
            id:t2
            x:20*dp+(parent.width-80*dp)/5+10*dp
            y:0*dp
            width: (parent.width-80*dp)/5
            picpath:"qrc:/picture/tj_p2.png"
            topv:"注射器使用次数"
            numbv: "487"
            dcolor: tabnumv===2?"#39B4FA":"#DEDEDE"
            onAllcli: {
                tabnum=1
                tabnumv=2
            }
        }
//        TJBYTop{
//            id:t3
//            x:20*dp+(parent.width-80*dp)/5*2+20*dp
//            y:0*dp
//            width: (parent.width-80*dp)/5
//            picpath:"qrc:/picture/tj_p3.png"
//            topv:"气罐使用次数"
//            numbv: "11425"
//            dcolor: tabnumv===3?"#10BA3F":"#DEDEDE"
//            onMorecli: {
//                tabnum=0
//            }
//            onAllcli: {
//                tabnum=1
//                tabnumv=3
//            }
//        }
        TJBYTop{
            id:t3
            x:20*dp+(parent.width-80*dp)/5*2+20*dp
            y:0*dp
            width: (parent.width-80*dp)/5
            picpath:"qrc:/picture/tj_p3.png"
            topv:"耗材编码统计"
            numbv: "11425"
            dcolor: tabnumv===3?"#10BA3F":"#DEDEDE"
            onMorecli: {
                tabnum=0
            }
            onAllcli: {
                tabnum=1
                tabnumv=3
            }
        }
        TJBYTop{
            id:t4
            x:20*dp+(parent.width-80*dp)/5*3+30*dp
            y:0*dp
            width: (parent.width-80*dp)/5
            picpath:"qrc:/picture/tj_p4.png"
            topv:"转盘使用次数"
            numbv: "145"
            dcolor: tabnumv===4?"#CD48FF":"#DEDEDE"
            onAllcli: {
                tabnum=1
                tabnumv=4
            }
        }
        TJBYTop{
            id:t5
            x:20*dp+(parent.width-80*dp)/5*4+40*dp
            y:0*dp
            width: (parent.width-80*dp)/5
            picpath:"qrc:/picture/tj_p5.png"
            topv:"胶垫使用次数"
            numbv: "246"
            dcolor: tabnumv===5?"#4440EC":"#DEDEDE"
            onAllcli: {
                tabnum=1
                tabnumv=5
            }
        }
    }
    Rectangle{
        id:alltab
        y:180*dp
        x:20*dp
        visible: tabnum
        height: parent.height - 200*dp
        width: parent.width-40*dp
        color: "#F7F7F7"
        radius: 8
        Text {
            x:20*dp
            y:20*dp
            text: "设备使用次数"
            font.bold: true
            font.pixelSize: config.fontsize + 3*dp
        }
        CustomComboCalendar{
            id:beginDate
            y:20*dp
            x:parent.width-440*dp
            editWidth: 200*dp
            height: 40*dp
            z:1
            onDateChanged: {
                var partData=CStatMaint.getPercentageStaticInfo(beginDate.getText(),endDate.getText())
                pieSeries.clear();

                if(partData["Syringe"]===0){
                    pieSeries.append("气罐",partData["Syringe"])
                }
                else
                {
                    pieSeries.append("气罐"+partData["Syringe"]+"%",partData["Syringe"])
                    pieSeries.find("气罐"+partData["Syringe"]+"%").labelVisible=true;
                }

                if(partData["AirBottle"]===0){
                    pieSeries.append("注射器",partData["AirBottle"])
                }
                else
                {
                    pieSeries.append("注射器"+partData["AirBottle"]+"%",partData["AirBottle"])
                    pieSeries.find("注射器"+partData["AirBottle"]+"%").labelVisible=true;
                }

                if(partData["Turntable"]===0){
                    pieSeries.append("转盘",partData["Turntable"])
                }
                else
                {
                    pieSeries.append("转盘"+partData["Turntable"]+"%",partData["Turntable"])
                    pieSeries.find("转盘"+partData["Turntable"]+"%").labelVisible=true;
                }

                if(partData["RubberPad"]===0){
                    pieSeries.append("胶垫",partData["RubberPad"])
                }
                else
                {
                    pieSeries.append("胶垫"+partData["RubberPad"]+"%",partData["RubberPad"])
                    pieSeries.find("胶垫"+partData["RubberPad"]+"%").labelVisible=true;
                }
            }
        }
        Text {
            y:20*dp
            x:parent.width-240*dp
            height: 40*dp
            width: 20*dp
            text: qsTr("-")
            // 设置水平和垂直方向的对齐方式为居中对齐
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
        CustomComboCalendar{
            id:endDate
            y:20*dp
            x:parent.width-220*dp
            editWidth: 200*dp
            height: 40*dp
            z:1
            onDateChanged: {
                var partData=CStatMaint.getPercentageStaticInfo(beginDate.getText(),endDate.getText())
                pieSeries.clear();
                if(partData["Syringe"]===0){
                    pieSeries.append("气罐",partData["Syringe"])
                }
                else
                {
                    pieSeries.append("气罐"+partData["Syringe"]+"%",partData["Syringe"])
                    pieSeries.find("气罐"+partData["Syringe"]+"%").labelVisible=true;
                }

                if(partData["AirBottle"]===0){
                    pieSeries.append("注射器",partData["AirBottle"])
                }
                else
                {
                    pieSeries.append("注射器"+partData["AirBottle"]+"%",partData["AirBottle"])
                    pieSeries.find("注射器"+partData["AirBottle"]+"%").labelVisible=true;
                }

                if(partData["Turntable"]===0){
                    pieSeries.append("转盘",partData["Turntable"])
                }
                else
                {
                    pieSeries.append("转盘"+partData["Turntable"]+"%",partData["Turntable"])
                    pieSeries.find("转盘"+partData["Turntable"]+"%").labelVisible=true;
                }

                if(partData["RubberPad"]===0){
                    pieSeries.append("胶垫",partData["RubberPad"])
                }
                else
                {
                    pieSeries.append("胶垫"+partData["RubberPad"]+"%",partData["RubberPad"])
                    pieSeries.find("胶垫"+partData["RubberPad"]+"%").labelVisible=true;
                }
            }
        }

        ChartView {
            id: chartView
            x:20*dp
            y:80*dp
            width: parent.width*0.4
            height: parent.height - y - 20*dp
            //            anchors.fill: parent
            legend.alignment: Qt.AlignBottom
            antialiasing: true
            animationOptions: ChartView.AllAnimations
            theme: ChartView.ChartThemeQt
            PieSeries {
                id: pieSeries

            }
        }

        ChartView
        {
            x:parent.width*0.42
            y:80*dp
            width: parent.width*0.58-20*dp
            height: parent.height - y - 20*dp
            legend.alignment: Qt.AlignBottom
            antialiasing: true   //反锯齿
            backgroundColor: "white"
            animationOptions: ChartView.NoAnimation


            //设置坐标轴
            BarCategoryAxis
            {
                id: axisX
                categories: ["注射器", "气罐", "转盘", "胶垫"]
                labelsVisible: true
            }

            ValueAxis
            {
                id: axisY
                min: 0
                max: CStatMaint.getMaxY(beginDate.getText(),endDate.getText())
                labelsColor:"#111111"
                tickCount: 6
                labelsVisible: true
            }

            // 柱形系列
            BarSeries
            {
                id: barSeries
                barWidth:0.4
                axisX: axisX
                axisY: axisY
                labelsPosition: AbstractBarSeries.LabelsInsideEnd//柱状条形图里面的数字位置
                labelsVisible: true		//柱状条形图里数字值是否显示，默认不显示
                BarSet {
                    id:barSet
                    color: "#FF9A3F"
                    values: CStatMaint.getStaticInfoByDate(beginDate.getText(),endDate.getText())
                }
            }
        }
    }
    Rectangle{
        id:jgtab
        y:180*dp
        x:20*dp
        visible: !tabnum
        height: parent.height - 200*dp
        width: parent.width-40*dp
        color: "#F7F7F7"
        radius: 8
        Text {
            x:20*dp
            y:20*dp
            text: "气罐保养指导"
            font.bold: true
            font.pixelSize: config.fontsize + 3*dp
        }

        Rectangle{
            x:20*dp
            y:80*dp
            width: 600*dp
            height: 400*dp
            Image {
                width: 560*dp
                height: parent.height*0.72
                x:20*dp
                y:20*dp
                source: "qrc:/picture/tj_pic.jpg"
                fillMode: Image.PreserveAspectFit
            }
        }

        Rectangle{
            x:640*dp
            y:80*dp
            width: 820*dp
            height: parent.height*0.8
            color: "white"
            Text {
                x:20*dp
                y:20*dp
                text: qsTr("气罐保养指导 \n\n查看压力容器储气罐的罐体顶上的压力安全阀是否正常。 \n\n时刻留意储气罐的压力表数值和位置的好坏与正常,释放压力时正常")
            }
        }


    }
    //  条码页
    StatMaintBarCode{
        y:180*dp
        x:20*dp
        visible: tabnumv === 3
        height: parent.height - 200*dp
        width: parent.width-40*dp
    }
}
